<#assign annotation = bali[0].annotation>
<#list annotation.factoryInterface.enclosedElements as x>
<#if x.kind.toString() == "METHOD">
<#if x.simpleName == "create">
<#assign validatedInterface = x.returnType>
<#assign validatedClass = x.parameters[0].asType()>
<#elseif x.returnType.asElement().simpleName == "Collection">
<#assign resultType = x.returnType.typeArguments[0]>
</#if>
</#if>
</#list>
package ${annotation.factoryInterface.enclosingElement.qualifiedName};

import javax.inject.Singleton;
import javax.inject.Inject;
import java.util.Set;
import java.util.HashSet;
import java.util.Collection;
import java.util.ArrayList;

/**
 *
 */
@Singleton
public class ${annotation.factoryInterface.simpleName}Impl
<#if (annotation.factoryInterface.superclass)??>
		extends ${annotation.factoryInterface.superclass}
</#if>
		implements ${annotation.factoryInterface.simpleName} {
	@Inject
	private Collection<${resultType}> validationResults;
<#list bali as v>
	@Inject
	private ${v.class.qualifiedName} ${v.class.simpleName?uncap_first};
</#list>

<#if !(annotation.factoryInterface.superclass)??>
	protected Collection<${validatedClass}Validation> validations = new ArrayList();
</#if>

	public ${annotation.factoryInterface.simpleName}Impl() {
<#list bali as v>
		validations.add(${v.class.simpleName?uncap_first});
</#list>
	}

	public ${validatedInterface} create(${validatedClass} entity) {
		return new ${validatedClass}Validation.Decorator(entity, validationResults, validations);
	}

	public Collection<${resultType}> getViolations() {
		return validationResults;
	}
}
